package huixue.cn.com.rxapp.rx;

import android.content.Intent;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import huixue.cn.com.rxapp.R;
import huixue.cn.com.rxapp.base.SimpleActivity;
import huixue.cn.com.rxapp.rx.adapter.MainAdapter;
import huixue.cn.com.rxapp.rx.entity.Item;
import huixue.cn.com.rxapp.rxjava2.JsutUtil;

public class RxJava2Activity extends SimpleActivity {

    @BindView(R.id.recyclerview)
    RecyclerView recyclerview;

    private MainAdapter mMainAdapter;

    private List<Item> mDatas;

    @Override
    public int getLayout() {
        return R.layout.activity_rx_java2;
    }

    @Override
    public void initView() {
        mDatas = new ArrayList<>();
        mDatas.add(new Item("range",null));
        mDatas.add(new Item("fromArray",null));
        mDatas.add(new Item("repeat",null));
        mDatas.add(new Item("amb",null));

    }

    @Override
    public void addEvent() {
        mMainAdapter = new MainAdapter(R.layout.layout_item_main,mDatas);


        LinearLayoutManager layoutManager = new LinearLayoutManager(this);
        layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
        recyclerview.setLayoutManager(layoutManager);

        recyclerview.addItemDecoration(new RecycleItemDecoration(10));

        mMainAdapter.setOnItemClickListener(((adapter, view, position) -> {
            Item item = mDatas.get(position);
            if(item.getAction()!=null){
                startActivity(new Intent(RxJava2Activity.this,item.getAction()));
            }else if(item.getName().equals("range")){
                //doSomething();
                JsutUtil.range();
            }else if(item.getName().equals("fromArray")){

            }else if(item.getName().equals("amb")){
                JsutUtil.doAmb();
            }
        }));
        recyclerview.setAdapter(mMainAdapter);
    }



}
